home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / c / mkid.lha / src / wmatch.c < prev   
C/C++ Source or Header  |  1991-02-01  |  830b  |  41 lines

  1. /* Copyright (c) 1986, Greg McGary */
  2. static char sccsid[] = "@(#)wmatch.c    1.1 86/10/09";
  3.  
  4. #include    "bool.h"
  5. #include    <ctype.h>
  6.  
  7. bool wordMatch();
  8.  
  9. /*
  10.     Does `name' occur in `line' delimited by non-alphanumerics??
  11. */
  12. bool
  13. wordMatch(name0, line)
  14.     char        *name0;
  15.     register char    *line;
  16. {
  17.     register char    *name = name0;
  18. #define IS_ALNUM(c)    (isalnum(c) || (c) == '_')
  19.  
  20.     for (;;) {
  21.         /* find an initial-character match */
  22.         while (*line != *name) {
  23.             if (*line == '\n')
  24.                 return FALSE;
  25.             line++;
  26.         }
  27.         /* do we have a word delimiter on the left ?? */
  28.         if (IS_ALNUM(line[-1])) {
  29.             line++;
  30.             continue;
  31.         }
  32.         /* march down both strings as long as we match */
  33.         while (*++name == *++line)
  34.             ;
  35.         /* is this the end of `name', is there a word delimiter ?? */
  36.         if (*name == '\0' && !IS_ALNUM(*line))
  37.             return TRUE;
  38.         name = name0;
  39.     }
  40. }
  41.